package cn.virens.common.project.generator.database.abstr;

import cn.virens.common.project.generator.database.datasource.info.TableInfo;
import cn.virens.common.project.generator.database.utils.PathBuilder;
import cn.virens.common.util.core.Assert;
import cn.virens.common.util.exception.APIException;

public abstract class AbstractGeneratorFileOutSimple extends AbstractGeneratorFileOut {
    protected AbstractGeneratorFileOutSimple(AbstractGenerator generator, String templatePath) {
        super(generator, templatePath);
    }

    @Override
    protected String output(TableInfo table) throws APIException {
        PathBuilder builder = new PathBuilder(getRootPath());

        this.addProject(builder, Assert.isNull(table));
        this.addSource(builder, Assert.isNull(table));

        this.addPackage(builder, Assert.isNull(table));
        this.addModule(builder, Assert.isNull(table));

        return str(builder, table);
    }

    protected abstract String str(PathBuilder builder, TableInfo table);

    /**
     * 添加项目路径
     */
    protected void addProject(PathBuilder builder, TableInfo table) {
    }

    /**
     * 添加包路径
     */
    protected void addPackage(PathBuilder builder, TableInfo table) {
    }

    /**
     * 添加源码路径
     */
    protected void addSource(PathBuilder builder, TableInfo table) {
        builder.append("src/main/java");
    }

    /**
     * 添加模块路径
     */
    protected void addModule(PathBuilder builder, TableInfo table) {
        builder.append(globalConfig.getModule());
        builder.append(table.getEntity());
    }
}
